package com.zjitc.book.mapper;

import com.zjitc.book.entity.Permission;
import com.zjitc.book.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from t_user where username = #{username}")
    public User getUserByUsername(@Param("username") String username);

    @Insert("insert into t_user(id,username,password) values (null,#{username},#{password})")
    public int addUser(User user);

    @Select("select COUNT(*) from t_user where username = #{username}")
    public boolean existsByUsername(@Param("username") String username);

    @Transactional
    public List<String> getPermissionByUsername(@Param("username") String username);

    @Select("select * from t_user")
    public List<User> getAllUsers();

    public List<Permission> getMenu(@Param("username") String username);
}
